package com.hhkj.study.admin.config.service.biz.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.hhkj.study.admin.config.entity.ConfigLink;
import com.hhkj.study.admin.config.model.podo.ConfigLinkDo;
import com.hhkj.study.admin.config.model.podo.ConfigLinkPo;
import com.hhkj.study.admin.config.model.req.ConfigLinkReq;
import com.hhkj.study.admin.config.model.res.ConfigLinkRes;
import com.hhkj.study.admin.config.service.base.ConfigLinkService;
import com.hhkj.study.admin.config.service.biz.ConfigLinkBizService;
import com.hhkj.study.admin.config.service.extend.ConfigLinkExtendService;
import com.ruoyi.common.base.biz.service.biz.BaseBizServiceImpl;
import com.ruoyi.common.cont.SysConst;
import com.ruoyi.common.exception.GlobalException;
import org.springframework.stereotype.Service;

/**
* ConfigLinkBizServiceImpl
*
* @author SERVER
* @since 2024-09-06
*/
@Service
public class ConfigLinkBizServiceImpl extends BaseBizServiceImpl<ConfigLink, ConfigLinkReq, ConfigLinkRes, ConfigLinkDo, ConfigLinkPo, ConfigLinkService, ConfigLinkExtendService> implements ConfigLinkBizService {
    @Override
    public boolean updatePublishFlag(ConfigLinkReq req) {
        ConfigLink configLink = this.getExtendService().getByIdNotNull(req.getId());
        if (configLink.getPublishedFlag().equals(req.getPublishedFlag())) {
            throw new GlobalException(SysConst.Flag.IS.getFlag().equals(req.getPublishedFlag()) ?
                    "已上架" : "已下架");
        }
        LambdaUpdateWrapper<ConfigLink> configLinkUpdate = new LambdaUpdateWrapper<>();
        configLinkUpdate.eq(ConfigLink::getId, req.getId())
                .set(ConfigLink::getPublishedFlag, req.getPublishedFlag());
        return this.getService().update(configLinkUpdate);
    }
}